package com.qingae.earn.dao.impl;

import java.sql.SQLException;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.qingae.earn.dao.BuyCaiPiaoDAO;
import com.qingae.earn.domain.BuyCaiPiao;
import com.qingae.util.LogUtil;

public class BuyCaiPiaoDAOImpl implements BuyCaiPiaoDAO {
	private SqlMapClient sqlMapClient;

	@Override
	public BuyCaiPiao insert(BuyCaiPiao buyCaiPiao) {
		try {
			buyCaiPiao.setId((Integer)sqlMapClient.insert("buy_caiPiao.insert", buyCaiPiao));
			return buyCaiPiao;
		} catch (SQLException e) {
			LogUtil.error("sql:buy_caiPiao.insert", e);
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public int update(BuyCaiPiao buyCaiPiao) {
		try {
			return sqlMapClient.update("buy_caiPiao.update", buyCaiPiao);
		} catch (SQLException e) {
			LogUtil.error("sql:buy_caiPiao.insert", e);
			e.printStackTrace();
		}
		return 0;
	}

	@Override
	public BuyCaiPiao getLastOrder() {
		try {
			return (BuyCaiPiao) sqlMapClient.queryForObject("buy_caiPiao.getLastOrder");
		} catch (SQLException e) {
			LogUtil.error("sql:buy_caiPiao.getLastOrder", e);
			e.printStackTrace();
		}
		return null;
	}


	public void setSqlMapClient(SqlMapClient sqlMapClient) {
		this.sqlMapClient = sqlMapClient;
	}
	
	
	
}